home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / FILEFIND.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  3KB  |  87 lines

  1. @echo off
  2. REM *******************************************************************
  3. REM *** FileFind - Use CEnvi to search this disk, or all disks, for ***
  4. REM *** ver.1      files matching any given file spec.  Print names ***
  5. REM ***            off all files found, and return find count.      ***
  6. REM *******************************************************************
  7. CEnvi %0.bat %1 %2
  8. GOTO CENVI_EXIT
  9.  
  10. main(argc,argv)
  11. {
  12.    if ( 2 != argc  ||  !strcmp("/?",argv[1])  ||  !stricmp("/help",argv[1])  ||  0 == argv[1][0] ) {
  13.       FindCount = 0;
  14.       Instructions();
  15.    } else {
  16.       FindCount = FindFiles(argv[1]);
  17.    }
  18.    return(FindCount);
  19. }
  20.  
  21. FindFiles(spec) // find files mathcing spec, and return number found
  22. {
  23.    // determine spec searching for to see if search all drives, all of one
  24.    // drive, or specified subbdirectories
  25.    NameParts = SplitFileName(spec);
  26.    if ( NameParts.dir[0] == 0 ) {
  27.       count = SearchAllDrives(spec);
  28.    } else if ( 2 == strlen(NameParts.dir)  &&  NameParts.dir[1] == ':' )
  29.       count = SearchOneDrive(NameParts.dir[0],spec+2);
  30.    else {
  31.       count = SearchSubdir(spec);
  32.    }
  33.    return(count);
  34. }
  35.  
  36. SearchSubdir(SearchSpec) // search from SearchSpec for all matching files
  37. {
  38.    List = Directory(SearchSpec,TRUE,FATTR_RDONLY|FATTR_HIDDEN|FATTR_SYSTEM|FATTR_SUBDIR|FATTR_ARCHIVE);
  39.    if ( NULL == List )
  40.       return(0);
  41.    DisplayFoundList(List);
  42.    return(1 + GetArraySpan(List));
  43. }
  44.  
  45. SearchOneDrive(DriveLetter,SearchSpec)
  46. {
  47.    sprintf(FullSearchSpec,"%c:\\%s",DriveLetter,SearchSpec);
  48.    return SearchSubDir(FullSearchSpec);
  49. }
  50.  
  51. SearchAllDrives(SearchSpec) // look on all valid drives
  52. {
  53.    TotalFound = 0;
  54.    for ( DriveLetter = 'C'; DriveLetter <= 'Z'; DriveLetter++ ) {
  55.       sprintf(DriveCurdir,"%c:.",DriveLetter);
  56.       if ( NULL != FullPath(DriveCurdir) ) {
  57.          TotalFound += SearchOneDrive(DriveLetter,SearchSpec);
  58.       }
  59.    }
  60.    return(TotalFound);
  61. }
  62.  
  63. DisplayFoundList(list)
  64. {
  65.    count = 1 + GetArraySpan(list);
  66.    for ( i = 0; i < count; i++ ) {
  67.       printf("%-45s  %-8d  %s",list[i].name,list[i].size,ctime(list[i].Write)+4);
  68.    }
  69. }
  70.  
  71. Instructions()
  72. {
  73.    printf("\a\n")
  74.    printf("FileFind.bat - Find File in directory tree or on any drive.\n")
  75.    printf("\n")
  76.    printf("SYNTAX: FileFind FileSpec\n")
  77.    printf("\n")
  78.    printf("Where:  FileSpec Specification to match in finding file\n")
  79.    printf("\n")
  80.    printf("Examples: FileFind q*.bak        Find all *.bak files on all hard drives\n")
  81.    printf("          FileFind E:q*.bak      Find all *.bak files on drive E:\n")
  82.    printf("          FileFind foo\\q*.bak    Find all *.bak in subdirectory foo and below\n")
  83.    printf("          FileFind E:\\foo\\q*.bak Find all *.bak in subdirectory E:\\foo and below\n")
  84. }
  85.  
  86. :CENVI_EXIT
  87.